<%@ page import="dao.Dao" %>
<%@ page import="domain.Car_User_Good" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: wangh
  Date: 2020/12/25
  Time: 18:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户购物车管理</title>
    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
    <script>
        function updateGoodNumber(sid, suserid) {
            let str = prompt("请输入你要修改的商品数量：")
            if (str) {
                location.href = "${pageContext.request.contextPath}/updateGoodNumberServlet?sid=" + sid + "&suserid=" + suserid + "&str=" + str;
            }
        }

        function deleteGoodFromCar(sid, suserid) {
            if (confirm("确定要从购物车删除吗?")) {
                location.href = "${pageContext.request.contextPath}/delGoodFromCarByIdServlet?sid=" + sid + "&suserid=" + suserid;
            }
        }

        function delAllShoppingCarGoods(suserid){
            if (confirm("您确定要清空购物车吗？")) {
                location.href = "${pageContext.request.contextPath}/delAllShoppingCarGoodsServlet?suserid="+suserid;
            }
        }
    </script>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String id = request.getParameter("id");
    Dao dao = new Dao();
    List<Car_User_Good> goodFromCarById = dao.findGoodFromCarById(Integer.valueOf(id));
    request.setAttribute("goodFromCarById", goodFromCarById);
%>
<div class="logoBar"
     style="height: 75px;background: #1d7ad9;font-size: 35px;font-weight: bolder;padding-left: 100px;padding-top: 12px;color: white;">
    电脑销售平台
</div>
<div class="container">
    <h3 style="text-align: center">用户购物车管理</h3>
    <div style="float: right;margin: 5px;">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/index.jsp">商城主页</a>
        <a class="btn btn-primary" href="javascript:delAllShoppingCarGoods(<%=id%>);">清空购物车</a>
    </div>
    <form>
        <table border="1" class="table table-bordered table-hover">
            <tr class="success">
                <th>商品品牌</th>
                <th>商品名称</th>
                <th>商品数量</th>
                <th>商品总价</th>
                <th>购买人名称</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${goodFromCarById}" var="cargoods" varStatus="s">
                <tr>
                    <td>${cargoods.cname_no1}</td>
                    <td>${cargoods.cname}</td>
                    <td>${cargoods.snumber}</td>
                    <td>${cargoods.stotalprice}</td>
                    <td>${cargoods.username}</td>
                    <td><a class="btn btn-default btn-sm"
                           href="javascript:updateGoodNumber(${cargoods.sid},${cargoods.suserid});">修改数量</a>
                        <a class="btn btn-default btn-sm" href="javascript:deleteGoodFromCar(${cargoods.sid},${cargoods.suserid});">删除</a>
                        <a href="${pageContext.request.contextPath}/OrderInfo.jsp?snumber=${cargoods.snumber}&sid=${cargoods.sid}&suserid=${cargoods.suserid}">
                            <button type="button" class="btn btn-danger">支付</button>
                        </a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>
    <div class="alert alert-warning alert-dismissible" role="alert">
        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
                aria-hidden="true">&times;</span></button>
        <strong>提示信息:</strong>${updateGoodNumberInfo}
    </div>
</div>
</body>
</html>
